Skip to content

Handle for infinite loop on recursive trait#5488

Merged
ondrejmirtes merged 14 commits intophpstan:2.1.xfrom
samsonasik:infinite-loop
Apr 19, 2026
Merged

Handle for infinite loop on recursive trait#5488
ondrejmirtes merged 14 commits intophpstan:2.1.xfrom
samsonasik:infinite-loop

Conversation

@samsonasik
Copy link
Copy Markdown
Contributor

@samsonasik samsonasik commented Apr 18, 2026

@BoyeMagnus @TomasVotruba if this can be patched here in phpstan, this should fix rector issue infinite loop on recursive trait usage

the test here I added cause phpunit error

➜  phpstan-src git:(infinite-loop) vendor/bin/phpunit tests/PHPStan/Type/FileTypeMapperTest.php |more
PHPUnit 11.5.52 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.16
Configuration: /Users/samsonasik/www/phpstan-src/phpunit.xml
Random Seed:   1776480340

.E.....                                                             7 / 7 (100%)

Time: 00:01.209, Memory: 150.73 MB

There was 1 error:

1) PHPStan\Type\FileTypeMapperTest::testRecursiveTraitUsedInAnonymousClassDoesNotLoopIndefinitely
Error: Maximum call stack size of 8339456 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?

/Users/samsonasik/www/phpstan-src/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php:108
/Users/samsonasik/www/phpstan-src/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php:117
/Users/samsonasik/www/phpstan-src/vendor/ondrejmirtes/better-reflection/src/Util/GetLastDocComment.php:22

@phpstan-bot
Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@samsonasik
Copy link
Copy Markdown
Contributor Author

Fixed 🎉 /cc @BoyeMagnus @TomasVotruba

@samsonasik
Copy link
Copy Markdown
Contributor Author

@ondrejmirtes ready for review 👍

@samsonasik
Copy link
Copy Markdown
Contributor Author

@ondrejmirtes ready for review 👍

CI notice is unrelated.

Comment thread tests/PHPStan/Type/FileTypeMapperTest.php Outdated
@ondrejmirtes
Copy link
Copy Markdown
Member

  1. The solution is not to clear cache like that, the solution is to update $variableCacheKey in FileTypeMapper in this branch.
  2. This is not how we usually test crashes and infinite runs. We test it by adding a test to AnalyserIntegrationTest.

@samsonasik
Copy link
Copy Markdown
Contributor Author

@ondrejmirtes

  1. do you mean update like this:
-$variableCacheKey = sprintf('v4-%s', ComposerHelper::getPhpDocParserVersion());
+$variableCacheKey = sprintf('v5-%s', ComposerHelper::getPhpDocParserVersion());

is next iterate rollback and run will still green again after last time green?

  1. I can try that, but this is isolated with unit code itself, so "integration" seems a bit too much

@samsonasik
Copy link
Copy Markdown
Contributor Author

@ondrejmirtes I've moved test to AnalyserIntegrationTest and increase cache key variableCacheKey value 10f93cd

Ready for merge 👍

@samsonasik samsonasik requested a review from staabm April 19, 2026 11:05
@ondrejmirtes ondrejmirtes merged commit 5ab83ce into phpstan:2.1.x Apr 19, 2026
654 of 655 checks passed
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you.

@samsonasik samsonasik deleted the infinite-loop branch April 19, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants